﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using System.IO;
using System.Xml;
using Reborn_WorldServer.App1AppHandler;

namespace Reborn_Server.App1AppHandler
{
    public class TrainerData
    {
        public string TrainerName;
        public long TrainerCreatureID;
        public string TrainsSkill;
        public decimal CharacterSkill;
        public decimal TrainedTo;
        public int AvailableTraining;
        public int CharacterCoins;
        
        public decimal TotalMagicLevels;
        public int RequiredMagicLevels;
        public int NextSchoolRequiredLevels;
        public int CurrentSchoolsKnown;

        public List<TrainerSpell> TrainerSpells = new List<TrainerSpell>();
        public List<TrainerWeaponSkill> TrainerWeaponSkills = new List<TrainerWeaponSkill>();

        public string toXML()
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("TrainerData");
            xmldoc.WriteAttributeString("TrainerName", TrainerName.ToString());
            xmldoc.WriteAttributeString("TrainerCreatureID", TrainerCreatureID.ToString());
            xmldoc.WriteAttributeString("TrainsSkill", TrainsSkill.ToString());
            xmldoc.WriteAttributeString("CharacterSkill", CharacterSkill.ToString());
            xmldoc.WriteAttributeString("AvailableTraining", AvailableTraining.ToString());
            xmldoc.WriteAttributeString("CharacterCoins", CharacterCoins.ToString());
            xmldoc.WriteAttributeString("TotalMagicLevels", TotalMagicLevels.ToString());
            xmldoc.WriteAttributeString("RequiredMagicLevels", RequiredMagicLevels.ToString());
            xmldoc.WriteAttributeString("CurrentSchoolsKnown", CurrentSchoolsKnown.ToString());
            xmldoc.WriteAttributeString("NextSchoolRequiredLevels", NextSchoolRequiredLevels.ToString());
            xmldoc.WriteAttributeString("TrainedTo", TrainedTo.ToString());

            string innerXml = "";
            foreach (TrainerSpell trainerSpell in TrainerSpells)
            {
                innerXml = innerXml + trainerSpell.toXML();
            }

            xmldoc.WriteStartElement("TrainerSpells");
            xmldoc.WriteRaw(innerXml);
            xmldoc.WriteEndElement();



            innerXml = "";
            foreach (TrainerWeaponSkill trainerWeaponSkill in TrainerWeaponSkills)
            {
                innerXml = innerXml + trainerWeaponSkill.toXML();
            }

            xmldoc.WriteStartElement("TrainerWeaponSkills");
            xmldoc.WriteRaw(innerXml);
            xmldoc.WriteEndElement();



            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }


}
